import Cookies from 'js-cookie'

function getValue(key) {
  let value = ''
  switch (globalConfig.storageType) {
    case 'ck': {
      value = Cookies.get(key)
      break
    }
    case 'ss': {
      value = sessionStorage.getItem(key)
      break
    }
    case 'ls': {
      value = localStorage.getItem(key)
      break
    }
    default:
      break
  }
  return value
}

function setValue(key, value) {
  switch (globalConfig.storageType) {
    case 'ck': {
      Cookies.set(key, value)
      break
    }
    case 'ss': {
      sessionStorage.setItem(key, value)
      break
    }
    case 'ls': {
      localStorage.setItem(key, value)
      break
    }
    default:
      break
  }
}

function removeValue(key) {
  switch (globalConfig.storageType) {
    case 'ck': {
      Cookies.remove(key)
      break
    }
    case 'ss': {
      sessionStorage.removeItem(key)
      break
    }
    case 'ls': {
      localStorage.removeItem(key)
      break
    }
    default:
      break
  }
}

// -------------------------------------分割线--------------------------------------------- //
// 定义浏览器存储中authToken的操作方法
export const authToken = 'Auth-Token'

export function getAuthToken() {
  return getValue(authToken)
}

export function setAuthToken(value) {
  setValue(authToken, value)
}

export function removeAuthToken() {
  removeValue(authToken)
}

// 定义浏览器存储中authLanguage的操作方法
export const authLanguage = 'Auth-Language'

export function getAuthLanguage() {
  return getValue(authLanguage)
}

export function setAuthLanguage(value) {
  setValue(authLanguage, value)
}

export function removeAuthLanguage() {
  removeValue(authLanguage)
}

// 定义浏览器存储中authMenu操作，auth-menu以当前路由为准，不需要存储，定义名称常量
export const authMenu = 'Auth-Menu'
